<link rel="stylesheet" href="/css/guess-index.css?v=10">
<div class="beijing"></div>
<?php if(isset($this->playList['showing_list']) && count($this->playList['showing_list'])){?>
    <?php if((int)$this->playList['no_play'] === 1){?>
        <script>
            $(function () {
                showNoplay();
            });
            function showNoplay() {
                $("#guess_div_no_play").show();
            }
        </script>
    <?php }?>
    <div class="changci">第 <span id="play_number">1</span> 场比赛</div>
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <?php if(isset($this->playList['showing_list']) && $this->playList['showing_list']){?>
                <?php foreach ($this->playList['showing_list'] as $item){?>
                <div class="swiper-slide"
                     data-id="<?php echo $item['id'];?>"
                     is-put="<?php echo $item['is_put'];?>"
                     target-name-a="<?php echo $item['type_a']['target_name'];?>"
                     target-name-b="<?php echo $item['type_b']['target_name'];?>"
                     target-name-c="<?php echo $item['type_c']['target_name'];?>"
                     target-id-a="<?php echo $item['type_a']['target_id'];?>"
                     target-id-b="<?php echo $item['type_b']['target_id'];?>"
                     target-id-c="<?php echo $item['type_c']['target_id'];?>"
                     data-number="<?php echo $item['play_number'];?>"
                     data-a="<?php echo $item['player_a_name'];?>"
                     data-b="<?php echo $item['player_b_name'];?>"
                >
                    <div class="lunbo">
                        <div class="left-team">
                            <img src="<?php echo $item['player_a_icon'];?>" alt="">
                            <div class="title"><?php echo $item['player_a_name'].'[主]';?></div>
                        </div>
                        <div class="time">
                            <div class="top">世界杯</div>
                            <div class="center"><?php echo $item['stop_time'];?></div>
                            <div class="bottom">截止</div>
                        </div>
                        <div class="right-team">
                            <img src="<?php echo $item['player_b_icon'];?>" alt="">
                            <div class="title"><?php echo $item['player_b_name'].'[客]';?></div>
                        </div>
                    </div>
                </div>
                <?php }?>
            <?php }?>
        </div>
        <!-- Add Arrows -->
        <div class="swiper-button-next jiantou left"></div>
        <div class="swiper-button-prev jiantou right"></div>
    </div>
    <div class="get-chance">今日剩余<span id="all-chance" rel="<?php echo $this->playList['share_time'];?>"><?php echo $this->playList['all_chance']??0;?></span>次竞猜机会</div>
    <div class="xy-jieguo">
        <div class="jieguo-list shengfu">
            <div class="wanfa">全场胜平负</div>
            <div class="bifen">待选</div>
        </div>
        <div class="jieguo-list quanchang">
            <div class="wanfa">半全场胜平负</div>
            <div class="bifen">待选</div>
        </div>
        <div class="jieguo-list fenshu">
            <div class="wanfa">全场比分</div>
            <div class="bifen">待选</div>
        </div>
    </div>
    <div class="tishi">猜中可获得积分：<span><span id="all_score">0</span>分</span></div>
    <div class="tijiao" score-a="<?php echo \Util\Config::get('ziyan_score_a');?>" score-b="<?php echo \Util\Config::get('ziyan_score_b');?>" score-c="<?php echo \Util\Config::get('ziyan_score_c');?>"></div>
    <div class="gonglue" onclick="showNoticeTmp()">玩法攻略</div>
<?php }else{?>
    <div style="width: 100%;height:2rem;line-height: 1rem;font-size: 0.3rem;text-align: center;margin-top: 1rem;">
        比赛暂时未开放，敬请期待！<br>
        首场比赛开放时间为：2018年06月12 23:00
    </div>
<?php }?>

<!--玩法弹框-->
<div class="zhezao-jingcai">
    <div class="wanfa-list">
        <div class="vs-title" id="this_play"></div>
        <div class="list1">
            <div class="list1-con"  data-id="1">胜</div>
            <div class="list1-con"  data-id="2">平</div>
            <div class="list1-con"  data-id="3">负</div>
        </div>
        <div class="list2">
            <div class="list2-con"  data-id="4">胜胜</div>
            <div class="list2-con"  data-id="5">胜平</div>
            <div class="list2-con"  data-id="6">胜负</div>
            <div class="list2-con"  data-id="7">平胜</div>
            <div class="list2-con"  data-id="8">平平</div>
            <div class="list2-con"  data-id="9">平负</div>
            <div class="list2-con"  data-id="10">负胜</div>
            <div class="list2-con"  data-id="11">负平</div>
            <div class="list2-con"  data-id="12">负负</div>
        </div>
        <div class="list3">
            <div class="list3-con"  data-id="13">1:0</div>
            <div class="list3-con"  data-id="14">2:0</div>
            <div class="list3-con"  data-id="15">2:1</div>
            <div class="list3-con"  data-id="16">3:0</div>
            <div class="list3-con"  data-id="17">3:1</div>
            <div class="list3-con"  data-id="18">3:2</div>
            <div class="list3-con"  data-id="19">4:0</div>
            <div class="list3-con"  data-id="20">4:1</div>
            <div class="list3-con"  data-id="21">4:2</div>
            <div class="list3-con"  data-id="22">5:0</div>
            <div class="list3-con"  data-id="23">5:1</div>
            <div class="list3-con"  data-id="24">5:2</div>
            <div class="list3-con   kuan"  data-id="25">胜其他</div>
            <div class="list3-con"  data-id="26">0:0</div>
            <div class="list3-con"  data-id="27">1:1</div>
            <div class="list3-con"  data-id="28">2:2</div>
            <div class="list3-con"  data-id="29">3:3</div>
            <div class="list3-con"  data-id="30">平其他</div>
            <div class="list3-con"  data-id="31">0:1</div>
            <div class="list3-con"  data-id="32">0:2</div>
            <div class="list3-con"  data-id="33">1:2</div>
            <div class="list3-con"  data-id="34">0:3</div>
            <div class="list3-con"  data-id="35">1:3</div>
            <div class="list3-con"  data-id="36">2:3</div>
            <div class="list3-con"  data-id="37">0:4</div>
            <div class="list3-con"  data-id="38">1:4</div>
            <div class="list3-con"  data-id="39">2:4</div>
            <div class="list3-con"  data-id="40">0:5</div>
            <div class="list3-con"  data-id="41">1:5</div>
            <div class="list3-con"  data-id="42">2:5</div>
            <div class="list3-con  kuan"  data-id="43">负其他</div>
        </div>
        <div class="jingcha-guanbi"></div>
        <div class="jingcha-queren"></div>
    </div>
</div>

<div class="guess_op_div" id="guess_div_success">
    <div class="guess_kuang_success">
        <div class="tip_content">
            <span class="tip_title">提交成功</span>
            <span class="tip_subtitle">记得赛后到个人中心查看结果哦</span>
        </div>
        <div class="tip_tip">带上紫燕回家吃饭</div>
        <div class="ok" rel="0" onclick="showAgin(this)"></div>
    </div>
</div>

<div class="guess_op_div" id="guess_div_error">
    <div class="s_icon"></div>
    <div class="guess_kuang_error">
        <div class="tip_close"></div>
        <div class="tip_content">
            <span class="tip_title" id="error_msg">嘿~传球时刻到了！<br>分享好友获得更多竞猜机会！</span>
        </div>
        <div class="tip_tip" id="error_tip">
            点击微信屏幕右上角<img src="http://ziyan-image.oss-cn-hangzhou.aliyuncs.com/front/alert/fen.png">分享好友继续燃动世界杯
        </div>
    </div>
</div>

<div class="guess_op_div" id="guess_div_no_play">
    <div class="guess_kuang_error">
        <div class="tip_close" onclick="$(this).parent().parent().hide();"></div>
        <div class="tip_content">
            <span class="tip_title" id="error_msg" style="line-height: 0.6rem;">当前开放比赛你已全部竞猜<br>请等待下场比赛开放</span>
        </div>
        <div class="tip_tip" id="error_tip">
            记得邀请小伙伴一起来竞猜！
        </div>
    </div>
</div>

<div class="guess_op_div" id="guess_div_notice_tmp">
    <div class="guess_kuang_notice">
        <div class="tip_content">
            <p style="color: #009640;line-height: 1rem;text-align: center;font-size: 0.25rem;">玩法帮助</p>
            <p style="line-height:0.45rem;color:#2A2A2A;font-size: 0.19rem;text-align: left;">
                <span style="color: #333;font-weight: bold;">1、玩法说明</span><br>
                竞猜全场胜平负：主队全场（不含加时赛和点球决战）胜、平、负结果。<br>
                竞猜半全场胜平负：主队上半场胜负平和全场胜负平（不含加时赛和点球决战）。<br>
                竞猜全场比分：全场比赛的比分结果（不含加时赛和点球决战） 。<br>
                <span style="color: #333;font-weight: bold;">2、温馨提示：</span><br>
                猜中全场胜负平可获得3分，猜中半、全场胜负平可获得9分，猜中全场比分可获得27分，三项一起竞猜，可有机会获得更多积分哦~<br>
            </p>
        </div>
        <div class="ok" onclick="$(this).parent().parent().hide();"></div>
    </div>
</div>

<script>
    function showNoticeTmp() {
        $("#guess_div_notice_tmp").show();
    }
    //切换比赛
    function showPlay() {
        //初始化
        $('.jieguo-list').removeClass('chk');
        $('.bifen').attr('data-id','');
        $('.bifen').text("待选");
        $(".tijiao").addClass('no-click');
        $('.list1').find('.list1-con').removeClass('xuanzhong');
        $('.list2').find('.list2-con').removeClass('xuanzhong');
        $('.list3').find('.list3-con').removeClass('xuanzhong');
        var all_score = 0;


        var target_dom = $(".swiper-slide-active");

        //提交按钮
        var is_put = target_dom.attr('is-put');
        if(parseInt(is_put) === 1){
            $(".tishi").show();
            $(".tijiao").attr('is-disable',1);
        }else{
            $(".tishi").hide();
            $(".tijiao").attr('is-disable',0);
        }

        //比赛场次
        var play_number = target_dom.attr('data-number');
        $("#play_number").html(play_number);

        //竞猜信息
        var target_name_a = target_dom.attr('target-name-a');
        var target_name_b = target_dom.attr('target-name-b');
        var target_name_c = target_dom.attr('target-name-c');
        var target_id_a = target_dom.attr('target-id-a');
        var target_id_b = target_dom.attr('target-id-b');
        var target_id_c = target_dom.attr('target-id-c');
        if(parseInt(target_id_a) > 0){
            $(".shengfu").addClass('chk');
            $(".shengfu").find('.bifen').attr('data-id',target_id_a);
            $(".shengfu").find('.bifen').html(target_name_a);

            $('.list1').find('.list1-con[data-id="'+target_id_a+'"]').addClass('xuanzhong');
            all_score += parseInt($('.tijiao').attr('score-a'));
        }
        if(parseInt(target_id_b) > 0){
            $(".quanchang").addClass('chk');
            $(".quanchang").find('.bifen').attr('data-id',target_id_b);
            $(".quanchang").find('.bifen').html(target_name_b);

            $('.list2').find('.list2-con[data-id="'+target_id_b+'"]').addClass('xuanzhong');
            all_score += parseInt($('.tijiao').attr('score-b'));
        }
        if(parseInt(target_id_c) > 0){
            $(".fenshu").addClass('chk');
            $(".fenshu").find('.bifen').attr('data-id',target_id_c);
            $(".fenshu").find('.bifen').html(target_name_c);

            $('.list3').find('.list3-con[data-id="'+target_id_c+'"]').addClass('xuanzhong');
            all_score += parseInt($('.tijiao').attr('score-c'));
        }
        $("#all_score").html(all_score);
    }

    //提交成功后二次弹框
    function showAgin(el) {
        var type = $(el).attr('rel');
        if(parseInt(type) === 3){
            $("#guess_div_error").find('.s_icon').show();
            $("#error_msg").html("嘿~传球时刻到了！<br>分享好友获得更多竞猜机会！").css('line-height','0.6rem');
            $("#guess_div_error").show();
            $("#guess_div_success").hide();
        }else if(parseInt(type) === 4){
            $("#guess_div_error").find('.s_icon').hide();
            $("#error_msg").html("今天竞猜机会已使用完").css('line-height','1.2rem');
            $("#error_tip").html('<a href="javascript:;" class="turnBtn" onclick="urlTo(\'/my/winning\')"></a>');
            $("#guess_div_error").show();
            $("#guess_div_success").hide();
        }else{
            $("#guess_div_error").hide();
            $("#guess_div_success").hide();
        }
    }

    $(function () {
        //初始化第一场比赛内容
        showPlay();

        //提交竞猜
        $(".tijiao").on('click',function () {
            var is_put = $(this).attr('is-put');
            var is_disable = $(this).attr('is-disable');
            var show_id = $(".swiper-slide-active").attr('data-id');
            var play_type_a = $(".shengfu").find('.bifen').attr('data-id');
            var play_type_b = $(".quanchang").find('.bifen').attr('data-id');
            var play_type_c = $(".fenshu").find('.bifen').attr('data-id');

            if(parseInt(is_disable) === 1){
                return false;
            }
            if(parseInt(is_put) === 1){
                return false;
            }

            if(!show_id){
                $("#guess_op_div").find('.bai').html('请选择竞猜的比赛');
                $("#guess_op_div").show();
                return false;
            }
            if(!parseInt(play_type_a) && !parseInt(play_type_b) && !parseInt(play_type_c)){
                $("#guess_op_div").find('.bai').html('请选择竞猜结果');
                $("#guess_op_div").show();
                return false;
            }
            var index = layer.msg('提交中，请稍等...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '50%', time:1000000});
            $.ajax({
                url  : '/guess/put',
                type : 'post',
                data : {
                    show_id:show_id,
                    play_type_a:play_type_a,
                    play_type_b:play_type_b,
                    play_type_c:play_type_c
                },
                dataType : 'json',
                success : function (msg) {
                    layer.close(index);
                    if (msg.code === 200) {
                        $("#guess_div_error").hide();
                        $("#guess_div_success").show();

                        //竞猜选项赋值
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-name-a',$('.list1-con[data-id="'+play_type_a+'"]').html());
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-name-b',$('.list2-con[data-id="'+play_type_b+'"]').html());
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-name-c',$('.list3-con[data-id="'+play_type_c+'"]').html());
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-id-a',play_type_a);
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-id-b',play_type_b);
                        $(".swiper-slide[data-id='"+show_id+"']").attr('target-id-c',play_type_c);
                        $(".swiper-slide[data-id='"+show_id+"']").attr('is-put',1);
                        $(".tijiao").attr('is-disable',1).addClass('no-click').attr('is-put',1);

                        //切换下一场未竞猜的比赛
                        var sort_index = $(".swiper-slide-active").index();
                        $(".swiper-slide").each(function (index, el) {
                            if(parseInt($(el).attr('is-put')) == 0){
                                sort_index = index;
                                return false;
                            }
                        });
                        swiper.slideTo(sort_index);

                        var all_chance = parseInt($("#all-chance").html());
                        $("#all-chance").html(all_chance-1);

                        if(msg.result){
                            $("#guess_div_success").find('.ok').attr('rel',msg.result);
                        }

                    } else {
                        if(msg.result === 1){
                            $("#error_tip").html('点击微信屏幕右上角<img src="http://ziyan-image.oss-cn-hangzhou.aliyuncs.com/front/alert/fen.png">分享好友继续燃动世界杯');
                            $("#guess_div_error").find('.s_icon').show();
                            $("#error_msg").css('line-height','0.6rem');
                        }else if(msg.result === 2){
                            $("#guess_div_error").find('.s_icon').hide();
                            $("#error_tip").html('吃吃鸡明天再来吧！');
                            $("#error_msg").css('line-height','1.2rem');
                        }else{
                            $("#guess_div_error").find('.s_icon').hide();
                        }
                        $("#error_msg").html(msg.message);

                        $("#guess_div_error").show();
                        $("#guess_div_success").hide();
                    }
                },
                error: function () {
                    layer.close(index);
                    $("#error_msg").html('系统繁忙，请 <a href="javascript:;" style="color: green;display: inline-block;" onclick="window.location.reload();">刷新</a> 后再试');
                    $("#guess_div_error").show();
                    $("#guess_div_error").find('.s_icon').hide();
                    $("#guess_div_success").hide();
                },
                complete: function () {
                }
            });
        });
    });
</script>
<script>
    var swiper = new Swiper('.swiper-container', {
        initialSlide: <?php echo $this->playList['show_sort']??0;?>,
        observer: true,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
        },
        on: {
            slideChangeTransitionEnd: function () {
                showPlay();
            }
        }
    });
    $(".tip_close").on('click',function () {
        $("#guess_div_error").hide();
        $("#guess_div_success").hide();
    });
    //点击选项，弹框
    $('.jieguo-list').on('click',function () {
        var dataA = $(".swiper-slide-active").attr('data-a');
        var dataB = $(".swiper-slide-active").attr('data-b');
        var dataId = $(".swiper-slide-active").attr('data-id');

        if(!dataId){
            return false;
        }

        var isput = $(".swiper-slide-active").attr('is-put');
        if(parseInt(isput) === 1){
            $("#guess_div_error").find('.s_icon').hide();
            $("#error_msg").html("你已参与过本场竞猜").css('line-height','1.2rem');
            $("#guess_div_error").show();
            $("#guess_div_success").hide();
            return false;
        }
        if(parseInt($("#all-chance").html()) === 0){
            if(parseInt($("#all-chance").attr('rel')) >= 3){
                $("#guess_div_error").find('.s_icon').hide();
                $("#error_msg").html("今天竞猜次数已达到上限").css('line-height','1.2rem');
                $("#error_tip").html('<a href="javascript:;" class="turnBtn" onclick="urlTo(\'/my/winning\')"></a>');
                $("#guess_div_error").show();
                $("#guess_div_success").hide();
            }else{
                $("#guess_div_error").find('.s_icon').show();
                $("#error_msg").html("嘿~传球时刻到了<br>分享好友获得更多竞猜机会！").css('line-height','0.6rem');
                $("#guess_div_error").show();
                $("#guess_div_success").hide();
            }
            return false;
        }
        $("#this_play").html(dataA+' VS '+dataB);
        $('.zhezao-jingcai').css({"display":"block"});
    });
    //选中的加背景色
    $('.list1-con').on('click',function () {
        $('.list1-con').removeClass('xuanzhong');
        $(this).addClass('xuanzhong');
    });
    $('.list2-con').on('click',function () {
        $('.list2-con').removeClass('xuanzhong');
        $(this).addClass('xuanzhong');
    });
    $('.list3-con').on('click',function () {
        $('.list3-con').removeClass('xuanzhong');
        $(this).addClass('xuanzhong');
    });

    //点击确认后，获取id，内容
    $('.jingcha-queren').on('click',function () {
        var all_score = 0;
        var id = $('.list1-con.xuanzhong').data("id");
        var con = $('.list1-con.xuanzhong').text();
        if(id){
            $('.shengfu').addClass('chk');
            $('.shengfu>.bifen').text(con);
            $('.shengfu>.bifen').attr("data-id",id);

            all_score += parseInt($('.tijiao').attr('score-a'));
        }else {
            $('.shengfu').removeClass('chk');
            $('.shengfu>.bifen').text("待选");
            $('.shengfu>.bifen').attr("data-id",0);
        }

        var id1=$('.list2-con.xuanzhong').data("id");
        var con1=$('.list2-con.xuanzhong').text();
        //判断是否选择
        if(id1){
            $('.quanchang').addClass('chk');
            $('.quanchang>.bifen').text(con1);
            $('.quanchang>.bifen').attr("data-id",id1);

            all_score += parseInt($('.tijiao').attr('score-b'));
        }else {
            $('.quanchang').removeClass('chk');
            $('.quanchang>.bifen').text("待选");
            $('.quanchang>.bifen').attr("data-id",0);
        }

        var id2=$('.list3-con.xuanzhong').data("id");
        var con2=$('.list3-con.xuanzhong').text();
        if(id2){
            $('.fenshu').addClass('chk');
            $('.fenshu>.bifen').text(con2);
            $('.fenshu>.bifen').attr("data-id",id2);

            all_score += parseInt($('.tijiao').attr('score-c'));
        }else {
            $('.fenshu').removeClass('chk');
            $('.fenshu>.bifen').text("待选");
            $('.fenshu>.bifen').attr("data-id",0);
        }
        if(id || id1 || id2){
            $(".tishi").show();
            $("#all_score").html(all_score);
            if($(".tijiao").attr('is-disable') == 0){
                if(parseInt($("#all-chance").html()) > 0){
                    $(".tijiao").removeClass('no-click').attr('is-put',0);
                }else{
                    $(".tijiao").addClass('no-click').attr('is-put',1);
                }
            }else{
                $(".tijiao").addClass('no-click').attr('is-put',1);
            }
        }
        //关闭弹框
        $('.zhezao-jingcai').css({"display":"none"});
    });
    $('.jingcha-guanbi').on('click',function () {
        $('.zhezao-jingcai').css({"display":"none"});
    });
    $('.left,.right').on('click',function () {
        showPlay();
    });
</script>
